# Courtesy of qemu-3dfx <liewkj@yahoo.com>

_realname=virglrenderer
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=0.9.1
pkgrel=1
pkgdesc='A virtual 3D GPU library, that allows the guest operating system to use the host GPU to accelerate 3D rendering'
arch=('any')
mingw_arch=('mingw64' 'mingw32' 'ucrt64' 'clang64' 'clang32')
url='https://virgil3d.github.io/'
license=(MIT)
depends=("${MINGW_PACKAGE_PREFIX}-libepoxy")
makedepends=("${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc")
_tag=virglrenderer-$pkgver
source=("virglrenderer-$pkgver.tar.bz2::https://gitlab.freedesktop.org/virgl/virglrenderer/-/archive/$_tag/virglrenderer-$_tag.tar.bz2" 
        'https://raw.githubusercontent.com/kjliew/qemu-3dfx/7a8c114a910826cda99f06c6dfdfd438b1bedf31/virgil3d/MINGW-packages/0001-Virglrenderer-on-Windows-and-macOS.patch')
sha256sums=('860cc3f0f1a448542a812b6e13909824eb3140b7b3283d068e9640487d50e6c0'
            'ee129b1d13ae72b630c4f6c25501344dee0b6fb33fe5a0b03a86759d9666ded9')

prepare() {
  cd virglrenderer-$_tag
  # https://gitlab.freedesktop.org/virgl/virglrenderer/-/issues/217
  patch -p1 -i ${srcdir}/0001-Virglrenderer-on-Windows-and-macOS.patch
}

build() {
  cd virglrenderer-$_tag
  MSYS2_ARG_CONV_EXCL="--prefix" \
  meson \
    --prefix="${MINGW_PREFIX}" \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    build

  ninja -C build
}

check() {
  cd virglrenderer-$_tag
  ninja -C build test || true
}

package() {
  cd virglrenderer-$_tag
  DESTDIR="$pkgdir" ninja -C build install
  install -D -m644 "${srcdir}/${_realname}-${_realname}-${pkgver}/COPYING" "${pkgdir}/${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
